﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ScytaleDecrypt.Model
{
    public class Dictionary
    {
        
        private String FilePath { get; set; }

        public String CurrentLanguage { get; set; }

        private HashSet<String> WordList { get; set; }

        private static Dictionary instance;

        public static Dictionary GetInstance{
            get
            {
                if (instance == null) {
                    instance = new Dictionary();
                }
                return instance;
            }
        }

        private Dictionary() {
            
        }

        public void ConstructWordList() {
            WordList = new HashSet<string>();
            switch (CurrentLanguage.ToLower()) {
                case("german"): {
                    FilePath = "Resource/german.dic";
                    break;
                }
                case("english"): {
                    FilePath = "Resource/english.dic";
                    break;
                }

            }
            LoadWordList();
        }

        public bool Contains( String word ) {
            return WordList.Contains(word);
        }

        private void LoadWordList() {
            using (StreamReader r = new StreamReader(FilePath)) {
                string line; 
                while((line = r.ReadLine()) != null) {
                    WordList.Add(line.ToLower());
                }
            }
        }

        
    }
}
